<?php
class Controller extends ServiceController {
    function index() {
        $fields = array('email', 'fio', 'phone', 'text');
        $data = $this->post($fields);
        extract($data);
        
        $mail = new PHPMailerLite();
        $mail->IsMail();
        $mail->SetFrom($email, $name);
        
		$set = new OptionsSet();
		$options = $set->getOne();
		$emails = explode(',', $options->getField('feedback_email'));
		foreach ($emails as $email) {
		  $mail->AddAddress($email);	
		}
		
		$mail->Subject  = "Сообщение с формы обратной связи";
        $mail->MsgHTML($this->_createText($data));      
        $mail->Send();
        
        $this->response('email_send');
    }
    
    function _createText($params) {
        extract($params);
        
        $result = '<b>Сообщение с формы обратной связи:</b> <br />';
        $result .= '<table>';
        $result .= '<tr><td>ФИО: </td><td>'.$fio.'<td>';
		$result .= '<tr><td>Телефон: </td><td>'.$phone.'<td>';
        $result .= '<tr><td>E-mail: </td><td>'.$email.'<td>';
        $result .= '<tr><td>Запрос: </td><td>'.wordwrap($text, 80, '<br />').'<td>';
        $result .= '</table>';
        return $result;
    }
}
?>